package com.usf.jprovider.schema.selector.value.split;

import javax.xml.bind.annotation.XmlAttribute;

import com.usf.jprovider.object.JObjectNode;
import com.usf.jprovider.object.env.Environment;
import com.usf.jprovider.tools.RandomTools;

public final class SplitRandomValue extends AbstractSplitValue {
	
	@XmlAttribute protected int startIndex;
	@XmlAttribute protected int endIndex;
	
	public SplitRandomValue() {
		super();
		startIndex = 0;
		endIndex = -1;
	}
	public int getStartIndex() {
		return startIndex;
	}
	public int getEndIndex() {
		return endIndex;
	}

	@Override
	protected int index(Environment env, JObjectNode node, int size) {
		return RandomTools.randomizeInteger(startIndex, size-1);
	}
	@Override
	protected int startIndex(Environment env, JObjectNode node, int size) {
		return startIndex;
	}
	@Override
	protected int endIndex(Environment env, JObjectNode node, int size) {
		if(endIndex < startIndex) return size -1;
		return endIndex;
	}
	@Override
	public String toQuery(String column) {
		return "LIKE '%" + column + "%'";
	}
}
